<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-L-admin1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <script src="/static/js/base.js"></script>
    <script src="/static/js/jquery.min.js"></script>
    <script type="text/javascript" src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        body {
            overflow: auto;
            background-color: #f1f1f1;
        }

        .body-content {
            display: block;
            background-color: #fff;
            min-width: 1800px;
            min-height: 1200px;
            margin: auto;
            margin-top: 10px;
            width: 98%;
            height: 98vh;
            overflow:auto;
        }

        .piece {
            border: 1px solid #8a8a8a;
            margin-left: 10px;
            display: inline-block;
        }

        .piece .title {
            width: 100%;
            height: 40px;
            line-height: 40px;
            background: rgba(118, 162, 6, 1);
            border: 1px solid rgba(138, 138, 138, 1);
            text-align: center;
            color: #fff;
            font-size: 19px;
        }

        .piece .content ul {
            margin: 0px;
            padding: 0px;
            display: inline-block;
        }

        .piece .content ul li {
            width: 100%;
            list-style: none;
            display: block;
            height: 35px;
            border-bottom: 1px solid #8A8A8A;
        }

        .piece .content ul li:nth-last-child(1) {
            border: none;
        }

        .piece .content ul li span {
            width: 120px;
            text-align: right;
            background: rgba(204, 204, 204, 1);
            display: inline-block;
            height: 35px;
            line-height: 35px;
            padding-right: 10px;
            padding-left: 10px;
        }
        #goods-parameter .content ul li span{
            width: 70px;
        }
        #goods-parameter .content ul li input{
            width: 80px;
        }
        #goods-process .content ul li span{
            width: 70px;
        }
        #goods-process .content ul li input{
            width: 75px;
        }
        #weight-data .content ul li span{
            width: 50px;
        }
        #weight-data .content ul li input{
            width: 100px;
        }
        #number-data .content ul li span{
            width: 50px;
        }
        #number-data .content ul li input{
            width: 100px;
        }
        #number-data .content ul li select{
            width: 100px;
        }
        #price-data .content ul li span{
            width: 120px;
        }
        #price-data .content ul li input{
            width: 100px;
        }
        #price-data .content ul li select{
            width: 100px;
        }
        #blank-parameter .content ul li span{
            width: 100px;
        }

        #blank-parameter .content ul li input{
            width: 100px;
        }

        #blank-parameter .content ul li select{
            width: 100px;
        }

        #product-data .content ul li span{
            width: 80px;
        }

        #product-data .content ul li input{
            width: 120px;
        }

        #product-data .content ul li select{
            width: 120px;
        }

        .piece .content ul li input {
            text-indent: 10px;
            border: none;
            width: 160px;
            height: 35px;
            line-height: 35px;
            padding: 0px;
            margin: 0px;
        }

        .piece .content ul li select {
            display: inline-block;
            text-indent: 10px;
            border: none;
            background: none;
            width: 160px;
            height: 35px;
            line-height: 35px;
            padding: 0px;
            margin: 0px;
        }

        .company-buy {
            position: absolute;
            top: 36px;
            left: 20px;
        }

        .company-sell {
            position: absolute;
            top: 36px;
            left: 340px;
        }

        .goods-data {
            position: absolute;
            top: 280px;
            left: 20px;
        }

        .goods-parameter {
            position: absolute;
            top: 280px;
            left: 335px;
        }

        .goods-process {
            position: absolute;
            top: 280px;
            left: 520px;
        }

        .blank-parameter {
            position: absolute;
            top: 280px;
            left: 700px;
        }

        .weight-data {
            position: absolute;
            top: 280px;
            left: 935px;
        }

        .number-data {
            position: absolute;
            top: 430px;
            left: 935px;
        }

        .price-data {
            position: absolute;
            top: 280px;
            left: 1120px;
        }

        .product-data{
            position: absolute;
            top: 280px;
            left: 1370px;
        }

        .goods-table{
            position: absolute;
            border-collapse: collapse;
            top:820px;
            left:30px;
            background-color: #eee;
            border-left:1px solid #000;
            border-bottom:1px solid #000;
        }
        .goods-table tr th{
            display: inline-block;
            border-right: 1px solid #000;
            border-top: 1px solid #000;
            border-bottom: 1px solid #000;
            width: 149px;
            height: 35px;
            text-align: left;
            text-indent: 1em;
            line-height: 35px;
        }
        .goods-table tr td{
            display: inline-block;
            width: 149px;
            height: 35px;
            line-height: 35px;
            text-align: left;
            border-right: 1px solid #000;
            border-top: 1px solid #000;
            text-indent: 1em;
        }
        .goods-table tbody tr:hover{
            background-color: #1Addee;
            color: #fff;
        }
        .goods-table tfoot tr td:nth-child(1){
            width: 449px;
        }
        .goods-table tbody,thead,tfoot{
            display: block;
            width: 1520px;
            overflow-x: hidden;
        }
        .goods-table tbody{
            width: 1520px;
            height: 144px;
            overflow-y: auto;
        }
        .button-a{
            position: absolute;
            top:1040px;
            left:30px;
            /* background-color: #eee; */
            width: 1500px;
        }
        .button-a a{
            display: inline-block;
            width: 120px;
            height: 35px;
            line-height: 35px;
            background-color: #00B050;
            border: 1px solid #92D050;
            color:#fff;
            text-align: center;
            font-size: 18px;
        }
        .button-a a:nth-last-child(1){
            float: right;
            background-color: #92D050;
        }
    </style>
</head>
<body>
<div class="body-content">
    <div class="piece company-buy">
        <div class="title">
            询价方
        </div>
        <div class="content">
            <ul>
                {volist name="company_html" id="value"}
                <li>
                    <span>{$value.name}:</span>
                    <input type="text" id="{$value.id}">
                </li>
                {/volist}
            </ul>
        </div>
    </div>
    <div class="piece company-sell">
        <div class="title">
            报价方
        </div>
        <div class="content">
            <ul>
                {volist name="my_html" id="value" key="key"}
                {php}if($key%2 == 0)continue;{/php}
                <li>
                    <span>{$value.name}</span>
                    <input type="text" id="{$value.id}" 
                        value='{eq name="$value.id" value="order_no"}{$data.order_no}{/eq}{eq name="$value.id" value="day"}{$data.day}{/eq}'>
                </li>
                {/volist}
            </ul>
            <ul>
                {volist name="my_html" id="value" key="key"}
                {php}if($key%2 != 0)continue;{/php}
                <li>
                    <span>{$value.name}</span>
                    <input type="text" id="{$value.id}" 
                        value='{eq name="$value.id" value="order_no"}{$data.order_no}{/eq}{eq name="$value.id" value="day"}{$data.day}{/eq}'>
                </li>
                {/volist}
            </ul>
        </div>
    </div>
    <div class="piece goods-data">
        <div class="title">
            产品信息
        </div>
        <div class="content">
            <ul>
                <li>
                    <span>产品标准:</span>
                    <select id="goods_standard" onchange="set_goods_name(this.value)">
                        <option value="HG/T20592-2009">HG/T20592-2009</option>
                        <option value="HG/T20615-2009">HG/T20615-2009</option>
                        <option value="非标法兰">非标法兰</option>
                    </select>
                </li>
                <li>
                    <span>产品名称:</span>
                    <select id="goods_name" onchange="set_goods_strand(this.value)">
                    </select>
                </li>
                <li id="goods-type-name-li">
                    <span>名称简称</span>
                    <input type="text" id="goods_type_name" disabled>
                </li>
                <!-- <li id="goods-piping-li">
                    <span>产品类型:</span>
                    <input type="text" id="goods_type_name2" 
                        onkeypress="set_goods_blank()"
                        onchange="set_goods_blank()">
                </li> -->
                <li id="goods-attr-li">
                    <span>规格:</span>
                    <input type="text" id="goods_attr" 
                        onkeypress="set_goods_blank()"
                        onchange="set_goods_blank()"  list="goods_attr_list">
                        <datalist id="goods_attr_list">
                            {volist name="data.attr" id="value"}
                            <option value="{$value.attr}">{$value.attr}</option>
                            {/volist}
                        </datalist>
                </li>
                <li id="goods-pressure-li">
                    <span>压力等级:</span>
                    <select id="goods_pressure" onchange="set_goods_blank()">
                        {volist name="data.pressure" id="value"}
                        <option value="{$value.pressure}">{$value.pressure}</option>
                        {/volist}
                    </select>
                </li>
                <li id="goods-pipe-li">
                    <span>管外径:</span>
                    <select type="text" id="goods_pipe" 
                        onkeypress="set_goods_blank()"
                        onchange="set_goods_blank()">
                    <option value="A">A</option>
                    <option value="B">B</option>
                    </select>
                </li>
                <li id="goods-thickness-li">
                    <span>壁厚(s):</span>
                    <input type="text" id="goods_name" 
                        onkeypress="set_goods_blank()"
                        onchange="set_goods_blank()">
                </li>
                <li id="goods-material-li">
                    <span>密封面:</span>
                    <input type="text" id="goods_ss" 
                        onkeypress="set_goods_blank()"
                        onchange="set_goods_blank()"  list="goods_ss_list">
                        <datalist id="goods_ss_list">
                            {volist name="data.ss" id="value"}
                            <option value="{$value.ss}">{$value.ss}</option>
                            {/volist}
                        </datalist>
                </li>
                <li>
                    <span>材质:</span>
                    <select id="goods_material" onchange="set_material_data(this.value)">
                        <option value="304">304</option>
                        <option value="316L">316L</option>
                        <option value="2205">2205</option>
                        <option value="2507">2507</option>
                    </select>
                </li>
                <li>
                    <span>密度:</span>
                    <input type="number" id="goods_md" disabled>
                </li>
            </ul>
        </div>
    </div>
    <div class="piece goods-parameter" id="goods-parameter">
        <div class="title">
            产品参数
        </div>
        <div class="content" name="product-data">
            <ul>
                <li id="R1-li">
                    <span>外径:</span>
                    <input type="number" id="R1" value="0" onchange="set_weight()">
                </li>
                <li id="R2-li">
                    <span>内径:</span>
                    <input type="number" id="R2" value="0" onchange="set_weight()">
                </li>
                <li id="R6-li">
                    <span>壁厚</span>
                    <input type="number" id="R6" value="0" onchange="set_weight()">
                </li>
                <li id="H1-li">
                    <span>片厚:</span>
                    <input type="number" id="H1" value="0" onchange="set_weight()">
                </li>
                <li id="R3-li">
                    <span>台阶直径:</span>
                    <input type="number" id="R3" value="0" onchange="set_weight()">
                </li>
                <li id="H2-li">
                    <span>台阶高度:</span>
                    <input type="number" id="H2" value="0" onchange="set_weight()">
                </li>
                <li id="H3-li">
                    <span>总高</span>
                    <input type="number" id="H3" value="0" onchange="set_weight()">
                </li>
                <li id="R4-li">
                    <span>根径</span>
                    <input type="number" id="R4" value="0" onchange="set_weight()">
                </li>
                <li id="R5-li">
                    <span>对焊口直径</span>
                    <input type="number" id="R5" value="0" onchange="set_weight()">
                </li>
                <li id="N1-li">
                    <span>孔数:</span>
                    <input type="number" id="N1" value="0" onchange="set_weight()">
                </li>
                <li id="R7-li">
                    <span>孔径:</span>
                    <input type="number" id="R7" value="0" onchange="set_weight()">
                </li>
                <li>
                    <span>体积(净)</span>
                    <input type="number" id="volume" disabled="false">
                </li>
                <li>
                    <span>体积(毛)</span>
                    <input type="number" id="mvolume" disabled="false">
                </li>
            </ul>
        </div>
    </div>
    <div class="piece goods-process" id="goods-process">
        <div class="title">
            加工参数
        </div>
        <div class="content" name="product-data">
            <ul>
                <li id="A1-li">
                    <span>
                        外径余量
                    </span>
                    <input type="number" id="A1" value="0" onchange="set_weight()">
                </li>
                <li id="A2-li">
                    <span>
                        内径余量
                    </span>
                    <input type="number" id="A2" value="0" onchange="set_weight()">
                </li>
                <li id="A7-li">
                    <span>
                        壁厚余量
                    </span>
                    <input type="number" id="A7" value="0" onchange="set_weight()">
                </li>
                <li id="A3-li">
                    <span>
                        片厚余量
                    </span>
                    <input type="number" id="A3" value="0" onchange="set_weight()">
                </li>
                <li id="A4-li">
                    <span>
                        总高余量
                    </span>
                    <input type="number" id="A4" value="0" onchange="set_weight()">
                </li>
                <li id="A5-li">
                    <span>
                        根径余量
                    </span>
                    <input type="number" id="A5" value="0" onchange="set_weight()">
                </li>
                <li id="A6-li">
                    <span>
                        对焊口余量
                    </span>
                    <input type="number" id="A6" value="0" onchange="set_weight()">
                </li>
            </ul>
        </div>
    </div>
    <div class="piece blank-parameter" id="blank-parameter">
        <div class="title">
            毛胚单价参数
        </div>
        <div class="content">
            <ul>
                <li>
                    <span>产品工艺</span>
                    <select id="technology">
                        <option value="1">锻压毛胚</option>
                        <option value="2">锻打毛胚</option>
                        <option value="3">割板毛胚</option>
                        <option value="4">卷板毛胚</option>
                    </select>
                </li>
                <li id="goods-pressing-li">
                    <span>锻压毛重:</span>
                    <select id="goods_pressing" onchange="set_price(this.value)"></select>
                </li>
                <li id="round_steel_price">
                    <span>圆钢材料单价:</span>
                    <input type="number" id="goods_material_amount">
                </li>
                <li id="round_steel_amount">
                    <span>圆钢切费</span>
                    <input type="number" id="goods_cutting_amount">
                </li>
                <li>
                    <span>加工费</span>
                    <select id="goods_forging_amount"></select>
                </li>
                <li id="goods_loss_amount_li">
                    <span>损耗费用</span>
                    <input type="number" id="goods_loss_amount">
                </li>
                <li>
                    <span>毛胚单价</span>
                    <input type="number" id="goods_price">
                </li>
            </ul>
        </div>
    </div>
    <div class="piece weight-data" id="weight-data">
        <div class="title">
            重量参数
        </div>
        <div class="content">
            <ul>
                <li>
                    <span>单毛重</span>
                    <input type="text" id="goods_weight1">
                </li>
                <li>
                    <span>单净重:</span>
                    <input type="text" id="goods_weight2">
                </li>
                <li>
                    <span>废料重:</span>
                    <input type="text" id="goods_weight3">
                </li>
            </ul>
        </div>
    </div>
    <div class="piece number-data" id="number-data">
        <div class="title">
            数量参数
        </div>
        <div class="content">
            <ul>
                <li>
                    <span>数量:</span>
                    <input id="number" type="number" value="1" onchange="set_number(this.value)">
                </li>
                <li>
                    <span>单位</span>
                    <select id="unit" onchange="set_unit(this.value)">
                        <option value="套">套</option>
                        <option value="片">片</option>
                        <option value="个">个</option>
                    </select>
                </li>
            </ul>
        </div>
    </div>
    <div class="piece price-data" id="price-data">
        <div class="title">
            费用参数
        </div>
        <div class="content">
            <ul>
                <li>
                    <span>固溶单价:</span>
                    <input type="number" id="goods_price1" value="0"
                           onkeypress="get_total_price()"
                           onchange="get_total_price()" disabled>
                </li>
                <li>
                    <span>固溶费用:</span>
                    <input type="number" id="goods_price2" value="0"
                           onkeypress="get_total_price()"
                           onchange="get_total_price()" disabled>
                </li>
                <li>
                    <span>探伤费用:</span>
                    <input type="number" id="goods_price3" value="0"
                           onkeypress="get_total_price()"
                           onchange="get_total_price()">
                </li>
                <li>
                    <span>运费单价:</span>
                    <input type="number" id="goods_price4" value="0"
                           onkeypress="get_total_price()"
                           onchange="get_total_price()">
                </li>

                <li>
                    <span>运费:</span>
                    <input type="number" id="goods_price5" value="0"
                           onkeypress="get_total_price()"
                           onchange="get_total_price()">
                </li>
                <li>
                    <span>加工费:</span>
                    <input type="number" id="goods_price6" value="0"
                           onkeypress="get_total_price()"
                           onchange="get_total_price()">
                </li>
                <li>
                    <span>不含税毛胚单价:</span>
                    <input type="number" id="goods_total_price" value="0"
                           onkeypress="get_total_price()"
                           onchange="get_total_price()">
                </li>
            </ul>
        </div>
    </div>
    <div class="piece product-data" id="product-data">
        <div class="title">
            内部参数
        </div>
        <div class="content">
            <ul>
                <li>
                    <span>车工费用:</span>
                    <input type="number" id="product_price1" value="0"
                           onkeypress="get_total_price()"
                           onchange="get_total_price()">
                </li>
                <li>
                    <span>包装费用:</span>
                    <input type="number" id="product_price2" value="0"
                           onkeypress="get_total_price()"
                           onchange="get_total_price()">
                </li>
                <li>
                    <span>管理费用:</span>
                    <input type="number" id="product_price3" value="0"
                           onkeypress="get_total_price()"
                           onchange="get_total_price()">
                </li>
                <li>
                    <span>税款:</span>
                    <input type="number" id="product_price4" value="8.7"
                            disabled
                            onkeypress="get_total_price()"
                            onchange="get_total_price()">
                </li>
                <li>
                    <span>业务提成:</span>
                    <input type="number" id="product_price5" value="0"
                           onkeypress="get_total_price()"
                           onchange="get_total_price()">
                </li>
                <li>
                    <span>利润(%):</span>
                    <input type="number" id="product_price6" value="0"
                           onkeypress="get_total_price()"
                           onchange="get_total_price()">
                </li>
                <li>
                    <span>利润(￥):</span>
                    <input type="number" id="pale_amount" value="0" 
                        onkeypress="get_total_price()"
                        onchange="get_total_price()">
                </li>
                <li>
                    <span>含税成品价:</span>
                    <input type="number" value="0" id="product_total_price"
                           onkeypress="get_total_price()"
                           onchange="get_total_price()">
                </li>
            </ul>
        </div>
    </div>
    <table class="goods-table" id="goods-table">
        {empty name="info.html"}
        <thead>
            <tr>
                <th>产品名称</th>
                <th>产品明细</th>
                <th>材质</th>
                <th>数量</th>
                <th>单位</th>
                <th>单重</th>
                <th>总重</th>
                <th>单价</th>
                <th>总价</th>
                <th>备注</th>
            </tr>
        </thead>
        <tbody id="goods-tbody">
            <tr id="goods-message-1">
                <td id="goods-name-td"></td>
                <td id="goods-attr-td"></td>
                <td id="goods-material-td"></td>
                <td id="goods-number-td">1</td>
                <td id="goods-unit-td">套</td>
                <td id="goods-weight-td"></td>
                <td id="goods-total-weight-td"></td>
                <td id="goods-price-td"></td>
                <td id="goods-total-price-td"></td>
                <td id="goods-info-td"></td>
            </tr>
            <tr id="goods-message-2">
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
            <tr id="goods-message-3">
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
            <tr id="goods-message-4">
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
        </tbody>
        <tfoot id="tfoot-total">
            <tr>
                <td colspan="3">合计</td>
                <td id="order-total-number"></td>
                <td></td>
                <td id="order-weight"></td>
                <td id="order-total-weight"></td>
                <td id="order-price"></td>
                <td id="order-total-price"></td>
                <td></td>
            </tr>
        </tfoot>
        {else}
        {php}echo $info['html']{/php}
        {/empty}
    </table>
    <div class="button-a">
        {eq name="userInfo.username" value="admin"}
            {empty name="info.html"}
            <a href="javascript:add();">保存</a>
            <a href="javascript:del();">删除</a>
            <!-- <a href="javascript:save();">修改</a> -->
            <a href="javascript:upload();">更新报价单</a>
            {else}
            <a href="javascript:adopt('{$info.order_no}');">通过</a>
            <a href="javascript:refuse('{$info.order_no}');">拒绝</a>
            <a href="/" style="display: none;">asd</a>
            {/empty}
        {else}

        {/eq}
    </div>
</div>
</body>
<script>
    var company_html_top = '{$company_html_top}',
        click_count = 0,
        weight = 0,
        mweight = 0,
        price = 0,
        goods_message_list = {},
        goods_number = 1,
        md = 0,
        goods_standard_name = '',
        gurongjiao = 0,
        goods_total_price = 0,
        goods_total_amount = 0,
        pale = 0,
        loss_price = 0,
        order_list = [],
        order_list_json = '{php}if(!empty($info["data"])){echo str_replace(["=\"","\">","\n"],["=\\","\">",""],json_encode($info["data"],JSON_UNESCAPED_UNICODE));}else{echo "";}{/php}',
        select_tr_option = {},
        goods_name = document.getElementById('goods_name');
    set_goods_name('HG/T20592-2009');
    set_material_data('304');
    get_total_price();
    set_weight();
    set_number(1);
    set_order_list();
    function set_order_list(){
        if(order_list_json){
            let jsonString = order_list_json.replace(/[\x00-\x1F\x7F]/g, '');
            jsonString = jsonString.replace(/=\"/g, '=\\\"');
            jsonString = jsonString.replace(/">/g, '\\">');
            order_list = JSON.parse(jsonString);
        }
    }
    function adopt(order_no){
        $.ajax({
            url: '/admin/order/adopt?order_no=' + order_no, // 你的 PHP 脚本的 URL
            type: 'post', // 请求类型，可以是 'GET' 或 'POST'  
            dataType: 'json', // 预期服务器返回的数据类型  
            data: {},
            success: function(res) { 
                if (res.code == 200){
                    layer.alert("通过成功", {icon: 6},function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.location.reload();
                        parent.layer.close(index);
                    });
                }
            }
        });
    }
    function refuse(order_no){
        $.ajax({
            url: '/admin/order/refuse?order_no=' + order_no, // 你的 PHP 脚本的 URL
            type: 'post', // 请求类型，可以是 'GET' 或 'POST'  
            dataType: 'json', // 预期服务器返回的数据类型  
            data: {},
            success: function(res) { 
                if (res.code == 200){
                    layer.alert("拒绝成功", {icon: 6},function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.location.reload();
                        parent.layer.close(index);
                    });
                }
            }
        });
    }
    var trs = document.getElementById('goods-tbody').getElementsByTagName('tr');  
    // 然后，遍历这些元素  <tr id="goods-message-2" style="background: rgb(161, 204, 238); color: rgb(255, 255, 255);">…</tr>
    for (var m = 0; m < trs.length; m++) {  
        // 为每个 <tr> 元素添加点击事件监听器  
        trs[m].addEventListener('click', function(e) {  
            if (e.currentTarget.style.background){
                e.currentTarget.style = '';
                select_tr_option[e.currentTarget.id] = 0;
            }else{
                select_tr_option[e.currentTarget.id] = 1;
                let id = e.currentTarget.id;
                let newStr = id.replace("goods-message-", "");  
                e.currentTarget.style = 'background: rgb(161, 204, 238); color: rgb(255, 255, 255);';
                id = parseInt(newStr);
                if(id > 1){
                    let index = (id - 2);
                    let obj = order_list[index];
                    set_goods_name(obj.goods_standard.value);
                    set_material_data(obj.goods_material.value);
                    get_total_price();
                    set_weight();
                    set_number(obj.number);
                    for(let key in obj){
                        console.log(key);
                        if(isObject(obj[key])){
                            document.getElementById(key).innerHTML = obj[key].innerHTML;
                            document.getElementById(key).value = obj[key].value;
                        }else{
                            if(obj[key].value)
                                document.getElementById(key).value = obj[key].value;
                        }
                    }
                }
            }
            // 或者，由于闭包的作用，你也可以直接使用 trs[i]（但注意在异步函数中可能会有问题）  
        });  
    }
    function set_goods_name(value) {

        document.getElementById('goods-attr-td').innerText = value;
        let list = type_list[value], string = '';
        list.forEach(item => {
            string += '<option value="' + item + '">' + item + '</option>'
        });
        goods_name.innerHTML = string;
        document.getElementById('goods_price').value = 0;
        if (value == '非标法兰') {
            // strand_data
            document.getElementById('goods-parameter').style = 'display:block;';
            document.getElementById('goods-process').style = 'display:block;';
            document.getElementById('blank-parameter').style = '';
            document.getElementById('weight-data').style = '';
            document.getElementById('number-data').style = '';
            document.getElementById('price-data').style = '';
            document.getElementById('product-data').style = '';
            document.getElementById('technology').innerHTML = '<option value="1">锻打毛胚</option>';
            document.getElementById('round_steel_price').style = 'display:block';
            document.getElementById('round_steel_amount').style = 'display:block';
            document.getElementById('goods-type-name-li').style = 'display:none';
            // document.getElementById('goods-piping-li').style = 'display:none';
            document.getElementById('goods-attr-li').style = 'display:none';
            document.getElementById('goods-pressure-li').style = 'display:none';
            document.getElementById('goods-pipe-li').style = 'display:none';
            document.getElementById('goods-thickness-li').style = 'display:none';
            document.getElementById('goods-material-li').style = 'display:none';
            document.getElementById('goods-pressing-li').style = 'display:none';   
            document.getElementById('goods_loss_amount_li').style = 'display:block';
        } else {
            document.getElementById('round_steel_price').style = 'display:none';
            document.getElementById('round_steel_amount').style = 'display:none';
            document.getElementById('goods-parameter').style = 'display:none;';
            document.getElementById('goods-process').style = 'display:none;';
            document.getElementById('blank-parameter').style = 'left:340px;';
            document.getElementById('weight-data').style = 'left:570px;';
            document.getElementById('number-data').style = 'left:570px;';
            document.getElementById('price-data').style = 'left:750px;';
            document.getElementById('product-data').style = 'left:1000px;';
            document.getElementById('technology').innerHTML = '<option value="1">锻压毛胚</option>';
            document.getElementById('goods-type-name-li').style = 'display:block';
            // document.getElementById('goods-piping-li').style = 'display:block';
            document.getElementById('goods-attr-li').style = 'display:block';
            document.getElementById('goods-pressure-li').style = 'display:block';
            document.getElementById('goods-pipe-li').style = 'display:block';
            document.getElementById('goods-thickness-li').style = 'display:block';
            document.getElementById('goods-material-li').style = 'display:block';  
            document.getElementById('goods-pressing-li').style = 'display:block';  
            document.getElementById('goods_loss_amount_li').style = 'display:none';
            set_goods_strand(list[0]);
        }
    }

    function set_material_data(value) {
        let data = material_value[value];
        material_selected = data;
        md = document.getElementById('goods_md').value = data.md;
        pale = data.pale;
        gurongjiao = document.getElementById('goods_price1').value = data.gurongjiao;
        document.getElementById('goods_material_amount').value = data.price;
        document.getElementById('goods_cutting_amount').value = data.amount;
        document.getElementById('goods_forging_amount').innerHTML = '';
        jiagongfei.forEach(item => {
            document.getElementById('goods_forging_amount').innerHTML += '<option value="' + item.price + '">' + item.name + '(' + item.price + ')</option>';
        });
        document.getElementById('product_price6').value = data.pale;
        document.getElementById('goods-material-td').innerText = value;
        get_total_price();
    }

    function set_goods_strand(value) {
        goods_standard_name = value;
        document.getElementById('goods_type_name').value = type_list_type_name[value];
        // document.getElementById('goods_type_name2').value = type_list_type_name[value];
        document.getElementById('goods_weight1').value = weight;
        document.getElementById('goods_price2').value = Math.round(weight * gurongjiao, 4);
        set_goods_blank();
        if (starnd_list[value]) {
            starnd_list.all.forEach(item => {
                document.getElementById(item + '-li').style = 'display:none';
            });
            starnd_list[value].forEach(item => {
                document.getElementById(item + '-li').style = 'display:block';
            });
        }
        if (value == '带颈平焊法兰') {
            document.getElementById('R2').disabled = true;
        } else {
            document.getElementById('R2').disabled = false;
        }
        document.getElementById('goods-name-td').innerText = value;
        get_total_price();
    }

    function get_total_price() {
        let goods_price1 = parseFloat(document.getElementById('goods_price1').value),
            goods_price2 = parseFloat(document.getElementById('goods_price2').value),
            goods_price3 = parseFloat(document.getElementById('goods_price3').value),
            goods_price4 = parseFloat(document.getElementById('goods_price4').value),
            goods_price5 = parseFloat(document.getElementById('goods_price5').value),
            product_price1 = parseFloat(document.getElementById('product_price1').value),
            product_price2 = parseFloat(document.getElementById('product_price2').value),
            product_price3 = parseFloat(document.getElementById('product_price3').value),
            product_price4 = parseFloat(document.getElementById('product_price4').value),
            product_price5 = parseFloat(document.getElementById('product_price5').value),
            product_price6 = parseFloat(document.getElementById('product_price6').value);
        let total_price = 0,pale = 0,w = 0;
        if (document.getElementById('goods_standard').value == '非标法兰') {
            let goods_material_amount = document.getElementById('goods_material_amount').value,
                goods_cutting_amount = document.getElementById('goods_cutting_amount').value,
                goods_forging_amount = document.getElementById('goods_forging_amount').value;
            total_price += parseFloat(goods_material_amount);
            total_price += parseFloat(goods_cutting_amount);
            total_price += parseFloat(goods_forging_amount);
            document.getElementById('goods_price').value = total_price.toFixed(2);
            w = mweight;
        }else{
            total_price += parseFloat(document.getElementById('goods_price').value);
            w = document.getElementById('goods_pressing').value;
            console.log(w);
        }
        //固溶费用 = 固溶单价 * 毛胚重量
        goods_price2 = goods_price1 * w;
        //赋值固溶费用
        document.getElementById('goods_price2').value = goods_price2;
        //运费 = 运费单价 * 毛胚重量
        goods_price5 = goods_price4 * w;
        //赋值运费
        document.getElementById('goods_price5').value = goods_price5;
        //探伤费用 + 固溶费用 + 运费 + 加工费;
        goods_total_price = goods_price2 + goods_price3 + goods_price5;
        product_total_price = product_price1 + product_price2 + product_price3 + product_price5;
        total_price = parseFloat(total_price + goods_total_price + product_total_price).toFixed(2);
        total_price = parseFloat(total_price * parseFloat(w)).toFixed(2);
        console.log(total_price);
        pale = ((product_price6 - 1)  * total_price/100, 2).toFixed(2);
        total_price = (parseFloat(total_price) + parseFloat(pale)).toFixed(2);
        document.getElementById('goods_total_price').value = total_price;
        document.getElementById('pale_amount').value = pale;
        document.getElementById('goods-price-td').innerText = total_price;
        document.getElementById('product_total_price').value = ((100 + product_price4) * total_price/100).toFixed(2);
        let number = document.getElementById('goods-number-td').innerText;
        document.getElementById('goods-total-price-td').innerText = (total_price * parseFloat(number)).toFixed(2);
    }

    function set_goods_blank() {
        let goods_data = {
                attr: document.getElementById('goods_attr').value,
                pressure: document.getElementById('goods_pressure').value,
                pipe:document.getElementById('goods_pipe').value,
                // piping: document.getElementById('goods_piping').value,
                ss: document.getElementById('goods_ss').value,
                name:document.getElementById('goods_name').value,
                material:document.getElementById('goods_material').value
            },
            string = '';
        $.ajax({
            url: '/fdata', // 你的 PHP 脚本的 URL
            type: 'post', // 请求类型，可以是 'GET' 或 'POST'
            dataType: 'json', // 预期服务器返回的数据类型
            data: goods_data,
            success: function (res) {
                console.log(res);
                if (res.code == 200) {
                    res.data.falan.forEach(item => {
                        string += '<option value="' + item.duanyazhongliang + '">' + item.changjia + '(' + item.duanyazhongliang + ')</option>';
                    });
                    weight = res.data['falan'][0].duanyazhongliang;
                    let result = res.data['falan'][0];
                    document.getElementById('goods_weight1').value = weight;
                    document.getElementById('goods-weight-td').innerText = weight;
                    // document.getElementById('goods-price').innerText = res.data.price[0].price;
                    if(res.data.price[0]){
                        price = res.data.price[0].price;
                    }else{
                        price = (parseFloat(weight) * parseFloat(material_selected.price)).toFixed(2);
                    }
                    document.getElementById('goods_price').value = price;
                    document.getElementById('goods_pressing').innerHTML = string;
                    document.getElementById('goods-total-weight-td').value = Math.round(weight * number, 4);
                    document.getElementById('goods-attr-td').innerHTML = result.attr + '-' + result.pressure + '-' + result.piping;
                    get_total_price();
                }
            }
        });
    }

    function set_weight(){
        let PI = 3.1415926,
            R1 = parseFloat(document.getElementById('R1').value),
            R2 = parseFloat(document.getElementById('R2').value),
            H1 = parseFloat(document.getElementById('H1').value),
            R3 = parseFloat(document.getElementById('R3').value),
            H2 = parseFloat(document.getElementById('H2').value),
            H3 = parseFloat(document.getElementById('H3').value),
            R4 = parseFloat(document.getElementById('R4').value),
            R5 = parseFloat(document.getElementById('R5').value),
            R6 = parseFloat(document.getElementById('R6').value),
            N1 = parseFloat(document.getElementById('N1').value),
            R7 = parseFloat(document.getElementById('R7').value),
            A1 = parseFloat(document.getElementById('A1').value),
            A2 = parseFloat(document.getElementById('A2').value),
            A3 = parseFloat(document.getElementById('A3').value),
            A4 = parseFloat(document.getElementById('A4').value),
            A5 = parseFloat(document.getElementById('A5').value),
            A6 = parseFloat(document.getElementById('A6').value),
            A7 = parseFloat(document.getElementById('A7').value);
        let ZH = H1;
        if (H3 > 0)
            ZH = H3 + H2;
        if ('带颈平焊法兰' == document.getElementById('goods_name').value){
            R2 = (R5-R6*2);
            document.getElementById('R2').value = R2;
        }
        //外径R1 内孔 R2 片厚 H1 台阶直径 R3 台阶高度 H2 总高 H3 根径 R4 对焊口直径 R5 壁厚 R6 孔数 N1 孔径 R7 外径余量 A1 内径余量 A2 片厚余量 A3 总高余量 A4 根径余量 A5 对焊口直径余量 A6
        //(PI/4) * (R1^2 * H1 + R3^2 * H2 + (R4^2 + R4 * R5 + R5^2) * (H3 - H1 - H2) - R2^2 * (H3 + H2) - R7^2* N1)
        let volume = (PI/4) * (R1**2 * H1 + R3**2 * H2 + (R4**2 + R4 * R5 + R5**2) * (H3 - H1 - H2) - R2**2 * ZH - R7**2 * N1 * H1),
            mvolume = (PI/4) * ((R1 + A1)**2 * (H1 + A3) + R3**2 * H2 + ((R4 + A5)**2 + (R4 + A5) * (R5 + A6) + (R5 + A6)**2) * (H3 - H1 - H2 + A3) - (R2 + A2)**2 * (ZH + A4));
            weight = (volume * md /1000000).toFixed(6),
            mweight = (mvolume * md /1000000).toFixed(6);
        // goods_weight1
        document.getElementById('goods_weight1').value = mweight;
        document.getElementById('goods_weight2').value = weight;
        document.getElementById('goods_weight3').value = (mweight - weight).toFixed(6);
        document.getElementById('goods-weight-td').innerHTML = weight;
        // document.getElementById('goods-')
        document.getElementById('volume').value = (volume/100).toFixed(4);
        document.getElementById('mvolume').value = (mvolume/100).toFixed(4);
        let number = document.getElementById('goods-number-td').innerText;
        document.getElementById('goods-total-weight-td').innerText = (weight * parseFloat(number)).toFixed(6);
        loss_price = (parseFloat(material_selected.loss) * weight).toFixed(2);
        document.getElementById('goods_loss_amount').value = loss_price;
        get_total_price();
    }

    function set_number(value){
        goods_number = value;
        document.getElementById('goods-number-td').innerText = value;
        let price = document.getElementById('goods-price-td').innerText;
        let weight = document.getElementById('goods-weight-td').innerText;
        let amount = parseFloat(price) * parseFloat(value)
            weight = parseFloat(weight) * parseFloat(value);
        document.getElementById('goods-total-price-td').innerText = amount;
        document.getElementById('goods-total-weight-td').innerText = weight;

    }

    function set_unit(value){
        document.getElementById('goods-unit-td').innerText = value;
    }

    function set_price(value){
        document.getElementById('goods-weight-td').innerText = value;
        let number = document.getElementById('goods-number-td').innerText;
        let price = parseFloat(number) * parseFloat(value);
        weight = value;
        document.getElementById('goods_weight1').value = value;
        document.getElementById('goods-total-weight-td').innerText = price;
        get_total_price();
    }

    function add(){
        click_count++;
        let string = '',object = {};
        let tr = document.getElementById('goods-message-1');
        let td = tr.getElementsByTagName('td');
        let select = document.getElementsByTagName('select'),input = document.getElementsByTagName('input');
        for(i=0;i<td.length;i++)
            string += '<td>' + td[i].innerText + '</td>';
        for(j=0;j<select.length;j++){
            object[select[j].id] = {};
            object[select[j].id].value = select[j].value;
            object[select[j].id].innerHTML = select[j].innerHTML;
        }
        for(k=0;k<input.length;k++)
            object[input[k].id] = input[k].value;
        order_list.push(object);
        let obj = document.getElementById('goods-message-' + (click_count + 1));
        if(obj){
            obj.innerHTML = string;
        }else{
            document.getElementById('goods-tbody').innerHTML += '<tr id="goods-message-"' + (click_count + 1) + '>' + string + '</tr>';
        }
        total_merge();
    }

    function del(){
        if (!select_tr_option){
            alert('未选择要删除的');
        }else{
            for(let item in select_tr_option){
                if(select_tr_option[item] == 0)continue;
                if (item == 'goods-message-1'){
                    return alert('第一个不能删除');
                }
                document.getElementById(item).style = 'display:none;';
                // let tds = document.getElementById(item).getElementsByTagName('td');
                // for (let index = 0; index < tds.length; index++) {
                //     tds[index].innerHTML = '';
                // }
                let newStr = item.replace("goods-message-", "");  
                let id = parseInt(newStr);
                let index = (id - 2);
                let obj = order_list[index];
                obj.is_del = 1;
            }
        }
    }

    function upload(){
        if(0 == order_list.length){
            alert('未保存任何数据');
        }
        let update_data = order_list;
        let goods_tbody_html = document.getElementById('goods-table').innerHTML;
        let amount = document.getElementById('order-total-price').innerText;
        let comapny = document.getElementById('comapny').value;
        let address = document.getElementById('address').value;
        let nickname = document.getElementById('nickname').value;
        let mobile = document.getElementById('mobile').value;
        let date = document.getElementById('date').value;
        $.ajax({
            url: '/admin/order/create', // 你的 PHP 脚本的 URL
            type: 'post', // 请求类型，可以是 'GET' 或 'POST'
            dataType: 'json', // 预期服务器返回的数据类型
            data: {
                goods_tbody_html:goods_tbody_html,
                update_data:update_data,
                amount:amount,
                company:comapny,
                address:address,
                nickname:nickname,
                mobile:mobile,
                date:date
            },
            success: function (res) {
                console.log(res);
                if (res.code == 200) {
                    alert('提交成功,等待审核');
                }
            }
        })
    }

    function total_merge(){
        let number = 0,td = [],total = {};
        let tr = document.getElementById('goods-tbody').getElementsByTagName('tr');
        let tfoot_td = document.getElementById('tfoot-total').getElementsByTagName('tr')[0].getElementsByTagName('td');
        for(i=1;i<tr.length;i++){
            td = tr[i].getElementsByTagName('td');
            for(j=3;j<td.length;j++){
                if(j == 4)continue;
                if(j == 6)continue;
                if(!td[j].innerText || td[j].innerText == '')continue;
                number = parseFloat(td[j].innerText);
                if (!total[j])total[j] = 0;
                total[j] = parseFloat(total[j]) + number;
            }
        }
        for(let index in total){
            if(total[index])
                tfoot_td[(index-2)].innerText = total[index];
        }
    }

    function get_company(value){
        $.ajax({
            url: '/company', // 你的 PHP 脚本的 URL
            type: 'post', // 请求类型，可以是 'GET' 或 'POST'
            dataType: 'json', // 预期服务器返回的数据类型
            data: {company:value},
            success: function (res) {
                console.log(res);
                if (res.code == 200) {
                    if (!res.data)return;
                    document.getElementById('address').value = res.data.address;
                    document.getElementById('nickname').value = res.data.nickname;
                    document.getElementById('mobile').value = res.data.mobile;
                }
            }
        });
    }

    // function set_weight(){
        // let value = 0,
        //     obj = {},
        //     volume = {},
        //     volume_data = ['R1', 'R2', 'H1', 'R3', 'H2', 'H3', 'R4', 'R5', 'R6', 'N1', 'R7', 'A1', 'A7', 'A3', 'A4', 'A5', 'A6'];
        // volume_data.forEach(item => {
        //     value = document.getElementById(item).value;
        //     volume[item] = value;
        // });
        // obj.volume = volume;
        // obj.volume.Md = md;
        // obj.type_name = goods_standard_name;
        // $.ajax({
        //     url: '/volume', // 你的 PHP 脚本的 URL
        //     type: 'post', // 请求类型，可以是 'GET' 或 'POST'
        //     dataType: 'json', // 预期服务器返回的数据类型
        //     data: obj,
        //     success: function (res) {
               
        //     }
        // });
    // }
</script>
</html>